From ffeb0a6a0f6800c73aeaabfe6d40bedc9db58096 Mon Sep 17 00:00:00 2001 From: robertlipe Date: Thu, 2 Jan 2014 02:32:12 +0000 Subject: [PATCH] Destinator fixes. --- gpsbabel/destinator.cc | 43 ++++++++++++++++++++---------------------- gpsbabel/garmin_fs.h | 1 + 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/gpsbabel/destinator.cc b/gpsbabel/destinator.cc index 4d213ec02..87344d1e9 100644 --- a/gpsbabel/destinator.cc +++ b/gpsbabel/destinator.cc @@ -60,7 +60,7 @@ gmsd_init(waypoint* wpt) return gmsd; } -static char* +static QString read_wcstr(const int discard) { int16_t* buff = NULL, c; @@ -91,7 +91,10 @@ read_wcstr(const int discard) } } xfree(buff); - return res; + QString rv = QString::fromUtf8(res); + xfree(res); + return rv; + //return res; } else { return NULL; } @@ -154,16 +157,15 @@ destinator_read_poi(void) gbfrewind(fin); while (!(gbfeof(fin))) { - char* str, *hnum; + QString str, hnum; double ll; garmin_fs_t* gmsd; if (count == 0) { str = read_wcstr(0); - if ((str == NULL) || (strcmp(str, DST_DYN_POI) != 0)) { + if ((str != DST_DYN_POI)) { fatal(MYNAME "_poi: Invalid record header!\n"); } - xfree(str); } else if (! read_until_wcstr(DST_DYN_POI)) { break; } @@ -178,33 +180,29 @@ destinator_read_poi(void) hnum = read_wcstr(0); /* house number */ str = read_wcstr(0); /* street */ - if (!str) { + if (str.isEmpty()) { str = hnum; - hnum = NULL; + hnum = QString(); } - if (str) { + if (!str.isEmpty()) { gmsd = gmsd_init(wpt); - if (hnum) { - str = xstrappend(str, " "); - str = xstrappend(str, hnum); + if (!hnum.isEmpty()) { + str += " "; + str += hnum; } - GMSD_SET(addr, str); + GMSD_SETSTRQ(addr, str); } - if ((str = read_wcstr(0))) { /* city */ + if ((str = read_wcstr(0), !str.isEmpty())) { /* city */ gmsd = gmsd_init(wpt); - GMSD_SET(city, str); - } - - if (hnum) { - xfree(hnum); + GMSD_SETSTRQ(city, str); } (void) read_wcstr(1); /* unknown */ - if ((str = read_wcstr(0))) { /* postcode */ + if ((str = read_wcstr(0), !str.isEmpty())) { /* postcode */ gmsd = gmsd_init(wpt); - GMSD_SET(postal_code, str); + GMSD_SETSTRQ(postal_code, str); } (void) read_wcstr(1); /* unknown */ @@ -235,15 +233,14 @@ destinator_read_rte(void) gbfrewind(fin); while (!(gbfeof(fin))) { - char* str; + QString str; waypoint* wpt; if (count == 0) { str = read_wcstr(0); - if ((str == NULL) || (strcmp(str, DST_ITINERARY) != 0)) { + if ((str != DST_ITINERARY)) { fatal(MYNAME "_itn: Invalid record header!\n"); } - xfree(str); } else if (! read_until_wcstr(DST_ITINERARY)) { break; } diff --git a/gpsbabel/garmin_fs.h b/gpsbabel/garmin_fs.h index c4e154519..e38193403 100644 --- a/gpsbabel/garmin_fs.h +++ b/gpsbabel/garmin_fs.h @@ -51,6 +51,7 @@ /* GMSD_SETSTR(a,b): a = gmsd field, b = null terminated source */ #define GMSD_SETSTR(a,b) if (gmsd && (b) && (b)[0]) { gmsd->a = xstrdup((b)); gmsd->flags.a = 1; } +#define GMSD_SETSTRQ(a,b) if (gmsd && !b.isEmpty()) { gmsd->a = xstrdup((b)); gmsd->flags.a = 1; } /* GMSD_SETNSTR(a,b,c): a = gmsd field, b = source, c = sizeof(source) */ #define GMSD_SETNSTR(a,b,c) if (gmsd && (b) && (b)[0]) { gmsd->a = xstrndup((b),(c)); gmsd->flags.a = 1; } -- 2.30.2